def isPrime(x):
    if x == 1: return False
    n = True
    z = x - 1
    while z > 1:
        if not x % z:
            n = False
            break
        z -= 1
    return n

e = input()
Y = 10000
if e <= y:
    print('0')
else:
    r = []
    for i in range(len(e)):
        for z in range(i + 1, len(e) + 1):
            x = int(e[i:z])
            if isPrime(x):
                r += [x]
    print(max(r) if r else 0)





